package GUI.Ventas.Facturacion;

import java.util.ArrayList;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;

import sale.entities.OrderVO;
import sale.entities.SaleVO;

import org.eclipse.swt.widgets.Button;
import org.eclipse.wb.swt.SWTResourceManager;

import client.entities.ClientVO;

public class PreFactura extends Dialog {

	protected Object result;
	protected Shell shell;
	SaleVO sale;
	ArrayList <OrderVO> ordenes = new ArrayList <OrderVO>();
	ClientVO c;
	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public PreFactura(Shell parent, int style, ClientVO cliente, SaleVO sale) {
		super(parent, style);
		setText("SWT Dialog");
		c=cliente;
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		
		
		shell = new Shell(getParent(), getStyle());
		shell.setSize(548, 350);
		shell.setText(getText());
		shell.setLayout(new FormLayout());
		
		Label lblTipoDeConsumo = new Label(shell, SWT.NONE);
		lblTipoDeConsumo.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblTipoDeConsumo = new FormData();
		fd_lblTipoDeConsumo.top = new FormAttachment(0, 61);
		fd_lblTipoDeConsumo.left = new FormAttachment(0, 25);
		lblTipoDeConsumo.setLayoutData(fd_lblTipoDeConsumo);
		lblTipoDeConsumo.setText("Tipo de Consumo");
		
		Label lblArticulosConsumidos = new Label(shell, SWT.NONE);
		lblArticulosConsumidos.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblArticulosConsumidos = new FormData();
		fd_lblArticulosConsumidos.top = new FormAttachment(lblTipoDeConsumo, 27);
		fd_lblArticulosConsumidos.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblArticulosConsumidos.setLayoutData(fd_lblArticulosConsumidos);
		lblArticulosConsumidos.setText("Articulos Consumidos");
		
		Label lblConsumicionTotal = new Label(shell, SWT.NONE);
		lblConsumicionTotal.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblConsumicionTotal = new FormData();
		fd_lblConsumicionTotal.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblConsumicionTotal.setLayoutData(fd_lblConsumicionTotal);
		lblConsumicionTotal.setText("Consumicion Total");
		
		Label lblCiente = new Label(shell, SWT.NONE);
		lblCiente.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblCiente = new FormData();
		fd_lblCiente.top = new FormAttachment(lblConsumicionTotal, 17);
		fd_lblCiente.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblCiente.setLayoutData(fd_lblCiente);
		lblCiente.setText("Ciente");
		
		Label lblDescuentoPorCliente = new Label(shell, SWT.NONE);
		lblDescuentoPorCliente.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblDescuentoPorCliente = new FormData();
		fd_lblDescuentoPorCliente.top = new FormAttachment(lblCiente, 0, SWT.TOP);
		fd_lblDescuentoPorCliente.left = new FormAttachment(lblCiente, 249);
		fd_lblDescuentoPorCliente.right = new FormAttachment(100, -88);
		lblDescuentoPorCliente.setLayoutData(fd_lblDescuentoPorCliente);
		lblDescuentoPorCliente.setText("Descuento por cliente");
		
		Label lblDescuentosAdicionales = new Label(shell, SWT.NONE);
		lblDescuentosAdicionales.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblDescuentosAdicionales = new FormData();
		fd_lblDescuentosAdicionales.top = new FormAttachment(lblCiente, 27);
		fd_lblDescuentosAdicionales.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblDescuentosAdicionales.setLayoutData(fd_lblDescuentosAdicionales);
		lblDescuentosAdicionales.setText("Descuentos Adicionales");
		
		Label lblTotalDescontado = new Label(shell, SWT.NONE);
		lblTotalDescontado.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblTotalDescontado = new FormData();
		fd_lblTotalDescontado.top = new FormAttachment(lblDescuentosAdicionales, 27);
		fd_lblTotalDescontado.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblTotalDescontado.setLayoutData(fd_lblTotalDescontado);
		lblTotalDescontado.setText("Total Descontado");
		
		Label lblTotalAPagar = new Label(shell, SWT.NONE);
		lblTotalAPagar.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_lblTotalAPagar = new FormData();
		fd_lblTotalAPagar.bottom = new FormAttachment(100, -10);
		fd_lblTotalAPagar.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		lblTotalAPagar.setLayoutData(fd_lblTotalAPagar);
		lblTotalAPagar.setText("Total a Pagar");
		
		Label tipo = new Label(shell, SWT.NONE);
		FormData fd_tipo = new FormData();
		fd_tipo.bottom = new FormAttachment(lblTipoDeConsumo, 0, SWT.BOTTOM);
		fd_tipo.left = new FormAttachment(lblTipoDeConsumo, 26);
		tipo.setLayoutData(fd_tipo);
		tipo.setText("New Label");
		
		Button btnBuscar = new Button(shell, SWT.NONE);
		btnBuscar.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		FormData fd_btnBuscar = new FormData();
		fd_btnBuscar.right = new FormAttachment(lblDescuentoPorCliente, -15);
		fd_btnBuscar.top = new FormAttachment(lblCiente, -7, SWT.TOP);
		btnBuscar.setLayoutData(fd_btnBuscar);
		btnBuscar.setText("Buscar");
		
		Label cliente = new Label(shell, SWT.NONE);
		FormData fd_cliente = new FormData();
		fd_cliente.top = new FormAttachment(lblConsumicionTotal, 17);
		fd_cliente.left = new FormAttachment(btnBuscar, -138, SWT.LEFT);
		fd_cliente.right = new FormAttachment(btnBuscar, -21);
		cliente.setLayoutData(fd_cliente);
		if(c == null){
		cliente.setText("No especificado");
		}
		else{
			cliente.setText(c.getName() + " " + c.getLastName());
			
		}
		Label lblNewLabel_1 = new Label(shell, SWT.NONE);
		FormData fd_lblNewLabel_1 = new FormData();
		fd_lblNewLabel_1.bottom = new FormAttachment(lblTotalDescontado, 0, SWT.BOTTOM);
		fd_lblNewLabel_1.left = new FormAttachment(tipo, 0, SWT.LEFT);
		lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);
		lblNewLabel_1.setText("New Label");
		
		Label articulos = new Label(shell, SWT.NONE);
		fd_lblConsumicionTotal.top = new FormAttachment(articulos, 16);
		FormData fd_articulos = new FormData();
		fd_articulos.bottom = new FormAttachment(100, -191);
		fd_articulos.left = new FormAttachment(lblTipoDeConsumo, 0, SWT.LEFT);
		fd_articulos.right = new FormAttachment(100, 125);
		articulos.setLayoutData(fd_articulos);
		articulos.setText("New Label");
		
		Label total = new Label(shell, SWT.NONE);
		FormData fd_total = new FormData();
		fd_total.bottom = new FormAttachment(lblTotalAPagar, 0, SWT.BOTTOM);
		fd_total.left = new FormAttachment(tipo, 0, SWT.LEFT);
		total.setLayoutData(fd_total);
		total.setText("New Label");
		
		Button btnIngresarNuevoDescuento = new Button(shell, SWT.NONE);
		FormData fd_btnIngresarNuevoDescuento = new FormData();
		fd_btnIngresarNuevoDescuento.top = new FormAttachment(lblDescuentosAdicionales, -7, SWT.TOP);
		fd_btnIngresarNuevoDescuento.left = new FormAttachment(btnBuscar, 0, SWT.LEFT);
		btnIngresarNuevoDescuento.setLayoutData(fd_btnIngresarNuevoDescuento);
		btnIngresarNuevoDescuento.setText("Ingresar Nuevo Descuento");
		
		Label descCliente = new Label(shell, SWT.NONE);
		FormData fd_descCliente = new FormData();
		fd_descCliente.bottom = new FormAttachment(lblCiente, 0, SWT.BOTTOM);
		fd_descCliente.left = new FormAttachment(lblDescuentoPorCliente, 6);
		descCliente.setLayoutData(fd_descCliente);
		descCliente.setText("New Label");
		
		for (int i = 0; i<sale.getOrders().size(); i++){
			ordenes.add(sale.getOrders().get(i));
			
		}
		
		int m = sale.getTableKey();
		if (m ==-2){
			tipo.setText("Delivery");
			cliente.setText(sale.getClient().getName() + " " +  sale.getClient().getLastName());
			
		}
		else{
		if (m== -1){
			tipo.setText("Mostrador");
		
		}
	
		else{
			tipo.setText("Mesa" + String.valueOf(m));
		}}
		}
	
	
	
	
}
